﻿<script type="text/javascript" language=javascript>
    hoursInDay = 24;
    minutesInHour = 60;
    $(function () {
        $("#datepicker").datepicker();
        $("#datepicker").datepicker("option", "dateFormat", "dd.mm.yy");
        $("#id")

        for (var i = 0; i < hoursInDay; i++) {
            $("<option>" + i + "</option>").appendTo($("#hours"));
        }

        for (var i = 0; i < minutesInHour; i++) {
            $("<option>" + i + "</option>").appendTo($("#minutes"));
        }
    });

    function showMessage(text) {
        var message = $("<div></div>");
        var now = new Date();
        message.html(now.toDateString() + " " + now.toLocaleTimeString() + " - " + text);
        message.appendTo($(".log"));
    }

    function launchApp(applicationId, name) {
        var date = $("#datepicker")[0].value.replace(/\//g,'.');
        var time = $("#hours")[0].value + ":" + $("#minutes")[0].value;
        $.ajax({
            url: '/Home/LaunchApplication',
            data: { applicationId: applicationId, date: date, time: time },
            success: function (param) {
                console.log(param == "False");
                if (param != "False") {
                    showMessage('Приложение "' + name.toString() + '" установлено в очередь.');
                }
                else {
                    showMessage('Некорректно выбрано время/дата. Выберите дату в ближайшем будущем.');
                }
            }
        });
    }
</script>
@model IEnumerable<ServiceDeclaration.ViewModels.ApplicationListItem>
<table>
<tr>
    <th>
        Название
    </th>
    <th>

    </th>
</tr>
@foreach (var application in Model)
{
    <tr>
        <td>@application.Name</td>
        <td><input type=button onclick="launchApp(@application.Id, '@application.Name')" value="Запустить!"/></td>
    </tr>
}
            
</table>



<div class="launchTimeSelect">
    <p>
        Date: <input type="text" id="datepicker">
    </p>
    <p>
        Time: <select id="hours"></select>:<select id="minutes"></select>
    </p>
</div>

<div class="log">
    
</div>

